You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR improves external reference loading in OpenAPI.NET by reusing documents within each load, bounding traversal depth, and detecting external reference-only cycles.
Changes:
Adds URI-based document reuse and a configurable depth limit, defaulting to 64.
Updates reference resolution, schema-sibling traversal, and stream cleanup.
Adds regression tests and documents loading behavior.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Reference-loading defects mishandle redirected URLs, omit discriminator mappings beneath $defs or in $ref siblings, and allow local reference chains to throw uncaught indexing exceptions.
No open issues 🎉
3 previously missed issues
In code that hasn't changed since last review
Use the final response URI as the source for relative references
For a description that redirects to another directory or host, this records the original URL rather than the final response URI. Without a BaseUrl override, relative external references are consequently fetched from the original location, and references back to the redirected root miss the cache. Carry the final response's RequestMessage.RequestUri out of RetrieveStreamAndFormatAsync and use it as the source URI (falling back to the requested URL when unavailable).
Load external references in discriminator mappings
This traversal omits discriminator Mapping and DefaultMapping references beneath $defs or in $ref siblings, which OpenApiWalker does not traverse. With LoadExternalRefs enabled, their external documents are never fetched and the mapped targets remain unresolved. Add these authored discriminator references to the pending schemas without following Target, and add a regression test for a discriminator beneath $defs.
Catch indexing errors when resolving local reference chains
With LoadExternalRefs = true and an empty validation rule set, a local reference such as #/components/schemas/A/properties (where A exists) now throws IndexOutOfRangeException from LoadAsync. The new chain validation resolves local references, but this filter catches indexing exceptions only for chains containing an external reference. Catch these exceptions for local chains too, retaining the existing break behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
Improves external ref file loading.
Type of Change
Related Issue(s)
None linked.
Changes Made
Testing
Affected suites passed; the full solution was not run:
dotnet test --project test\Microsoft.OpenApi.Readers.Tests\Microsoft.OpenApi.Readers.Tests.csproj -c Release --no-restore --no-progress— passed, 665 tests.dotnet test --project test\Microsoft.OpenApi.Tests\Microsoft.OpenApi.Tests.csproj -c Release --no-restore --no-progress— passed, 1,309 tests.dotnet build src\Microsoft.OpenApi\Microsoft.OpenApi.csproj -c Release --no-restore— passed, both targets, no warnings.Checklist
Versions applicability
See the contributing guidelines for more information about how patches are applied across multiple versions.
Additional Notes
Earlier-version applicability has not been evaluated.